package com.jrx.anytxn.transaction.mapper.ext;

import com.jrx.anytxn.transaction.entity.AmStageRepaymentPlanInfo;
import com.jrx.anytxn.transaction.mapper.base.AmStageRepaymentPlanInfoMapper;
import com.jrx.anytxn.transaction.mapper.base.AmStageRepaymentPlanInfoMapper;
import org.apache.ibatis.annotations.Param;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * 还款计划扩展
 *
 * @author haopu.zheng
 * date  2019/7/25
 **/
public interface ExtAmStageRepaymentPlanInfoMapper extends AmStageRepaymentPlanInfoMapper {

    /**
     * 通过贷款ID及状态(数组传值)获取贷款计划
     *
     * @param loanId     订单id
     * @param status     状态数组
     * @param customerId 客户id
     * @param tenantId   租户id
     * @return java.util.List<com.jrx.anytxn.transaction.entity.AmStageRepaymentPlanInfo>
     * @author : zhenghaopu
     * date: 2019/9/25
     */
    List<AmStageRepaymentPlanInfo> selectRepaymentPlanInfoListByLoanIdAndStatus(@Param(value = "loanId") String loanId,
                                                                           @Param(value = "statusArrays") String[] status,
                                                                           @Param(value = "customerId") String customerId,
                                                                           @Param("tenantId") String tenantId);

    /**
     * 批量插入还款计划
     *
     * @param amRepaymentPlanInfoList 还款计划列表
     * @return void
     * @author : zhenghaopu
     * date: 2019/9/25
     */
    void insertAmStageRepaymentPlanInfoList(List<AmStageRepaymentPlanInfo> amRepaymentPlanInfoList);

    /**
     * 根据条件查询还款计划数据
     *
     * @param cond 条件
     * @return 还款计划数据
     */
    List<AmStageRepaymentPlanInfo> selectByCondSelective(AmStageRepaymentPlanInfo cond);

    ArrayList<AmStageRepaymentPlanInfo> selectPlanListByCondSelective(@Param("customerId") String customerId, @Param("tenantId") String tenantId, @Param("loanId") String loanId);

    /**
     * 根据条件查询还款计划
     *
     * @param loanId
     * @param status
     * @param customerId
     * @param tenantId
     * @return
     */
    List<AmStageRepaymentPlanInfo> selectByLoanIdAndStatus(@Param(value = "loanId") String loanId,
                                                      @Param(value = "statusList") List<String> status,
                                                      @Param(value = "customerId") String customerId,
                                                      @Param(value = "tenantId") String tenantId);

    /**
     * 批量更新还款计划（作用于联机）
     *
     * @param amRepaymentPlanInfos
     * @return
     */
    int batchUpdatePlan(List<AmStageRepaymentPlanInfo> amRepaymentPlanInfos);

    /**
     * 批量更新还款计划（作用于批量）
     *
     * @param amRepaymentPlanInfos
     * @return
     */
    int batchUpdatePlanForBatch(List<AmStageRepaymentPlanInfo> amRepaymentPlanInfos);

    /**
     * 根据主键及客户id及租户id修改还款计划
     *
     * @param amRepaymentPlanInfo
     * @return
     */
    int updateByIdAndCustomerIdAndTenantId(AmStageRepaymentPlanInfo amRepaymentPlanInfo);

    /**
     * 根据订单号、期数、状态、客户id、租户id查询还款计划
     *
     * @param loanId
     * @param customerId
     * @param tenantId
     * @param billingTenor
     * @param status
     * @return
     */
    AmStageRepaymentPlanInfo selectByLoanIdAndBillingTenor(@Param(value = "loanId") String loanId,
                                                      @Param(value = "customerId") String customerId,
                                                      @Param(value = "tenantId") String tenantId,
                                                      @Param(value = "billingTenor") Integer billingTenor,
                                                      @Param(value = "statusList") List<String> status);

    /**
     * 根据还款计划状态获取还款计划
     *
     * @param planStatus
     * @return
     */
    List<AmStageRepaymentPlanInfo> selectByStatusAndPaymentDate(@Param(value = "planStatus") String planStatus,
                                                           @Param(value = "today") Date today,
                                                           @Param(value = "lastProcessingDay") Date lastProcessingDay);

    /**
     * 根据更新时间查询还款计划表
     *
     * @param startTime
     * @param endTime
     * @return
     */

    List<AmStageRepaymentPlanInfo> selectRepaymentPlanInfoListByUpdateTimeSelective(@Param(value = "startTime") String startTime,
                                                                               @Param(value = "endTime") String endTime);

    /**
     * 根据loanid和更新时间查询还款计划
     *
     * @param loanId
     * @param customerId
     * @param tenantId
     * @param startTime
     * @param endTime
     * @return
     */
    List<AmStageRepaymentPlanInfo> selectRepaymentPlanInfoListByUpdateTimeAndLoanIdSelective(@Param(value = "loanId") String loanId, @Param(value = "customerId") String customerId, @Param(value = "tenantId") String tenantId, @Param(value = "startTime") String startTime, @Param(value = "endTime") String endTime);

    /**
     * 根据产品ID和还款日期查询还款计划
     *
     * @param productId
     * @param paymentDueDate
     * @return
     */
    List<AmStageRepaymentPlanInfo> selectByProductIdAndPaymentDueDate(@Param(value = "productId") String productId, @Param(value = "paymentDueDate") Date paymentDueDate);

    AmStageRepaymentPlanInfo selectByLoanIdAndTenor(@Param("customerId") String customerId, @Param("tenantId") String tenantId,
                                               @Param("channel") String channel, @Param("loanId") String loanId,
                                               @Param("billingTenor") Integer billingTenor);

    /**
     * 查询当前逾期还款计划
     *
     * @param loanId
     * @param customerId
     * @param tenantId
     * @return
     */
    AmStageRepaymentPlanInfo selectMaxOverPlan(@Param(value = "loanId") String loanId, @Param(value = "customerId") String customerId, @Param(value = "tenantId") String tenantId);


    /**
     * 根据条件查询还款计划 （排除取消的）
     *
     * @param loanId
     * @param customerId
     * @param tenantId
     * @return
     */
    List<AmStageRepaymentPlanInfo> selectByLoanId(@Param(value = "loanId") String loanId,
                                             @Param(value = "customerId") String customerId,
                                             @Param(value = "tenantId") String tenantId);

    /**
     * 根据条件查询还款计划升序 （排除取消和未抛账的）
     *
     * @param loanId
     * @param customerId
     * @param tenantId
     * @return
     */
    List<AmStageRepaymentPlanInfo> selectByLoanIdAsc(@Param(value = "loanId") String loanId,
                                                @Param(value = "customerId") String customerId,
                                                @Param(value = "tenantId") String tenantId);

    /**
     * 累计代偿次数统计
     *
     * @param loanId
     * @param customerId
     * @param tenantId
     * @return
     */
    int selectCountByCmps(@Param(value = "loanId") String loanId,
                          @Param(value = "customerId") String customerId,
                          @Param(value = "tenantId") String tenantId);

    /**
     * 汇总查询还款计划
     *
     * @param customerId
     * @param tenantId
     * @param loanIdList
     * @param startDate
     * @param endDate
     * @return
     */
    List<AmStageRepaymentPlanInfo> selectByLoanIdAndStartDateAndEndDate(@Param(value = "customerId") String customerId,
                                                                   @Param(value = "tenantId") String tenantId,
                                                                   @Param(value = "loanIdList") List<String> loanIdList,
                                                                   @Param(value = "startDate") Date startDate,
                                                                   @Param(value = "endDate") Date endDate,
                                                                   @Param(value = "planStatusList") List<String> planStatusList);

    /**
     * 根据 订单列表，开始时间，结束时间 还款计划明细
     *
     * @param customerId
     * @param tenantId
     * @param loanIdList
     * @param paymentDueDate
     * @return
     */
    List<AmStageRepaymentPlanInfo> selectByLoanIdList(@Param(value = "customerId") String customerId,
                                                 @Param(value = "tenantId") String tenantId,
                                                 @Param(value = "loanIdList") List<String> loanIdList,
                                                 @Param(value = "paymentDueDate") Date paymentDueDate);


    /**
     * 状态，客户，租户编号(订单号期次排序) 获取贷款计划
     *
     * @param loanIdList 订单列表
     * @param customerId 客户id
     * @param tenantId   租户id
     */
    List<AmStageRepaymentPlanInfo> selectByLoanIdListAndStatus(@Param(value = "loanIdList") List<String> loanIdList,
                                                          @Param(value = "customerId") String customerId,
                                                          @Param(value = "tenantId") String tenantId,
                                                          @Param(value = "planStatusList") List<String> planStatusList);

    /**
     * 指定期次之前是否已经结清
     *
     * @param loanId
     * @param customerId
     * @param tenantId
     * @return
     */
    int selectByLoanIdAndBillingTenorAndPlanStatusList(@Param(value = "loanId") String loanId,
                                                       @Param(value = "customerId") String customerId,
                                                       @Param(value = "tenantId") String tenantId,
                                                       @Param(value = "billingTenor") Integer billingTenor,
                                                       @Param(value = "planStatusList") List<String> planStatusList);


    List<AmStageRepaymentPlanInfo> selectRepaymentPlanInfoListByUpdateTimeAndLoanId(@Param(value = "loanId") String loanId, @Param(value = "customerId") String customerId, @Param(value = "tenantId") String tenantId, @Param(value = "startTime") String startTime);

    /**
     * 根据条件查询还款计划
     *
     * @param loanId
     * @param status
     * @param customerId
     * @param tenantId
     * @return
     */
    List<AmStageRepaymentPlanInfo> selectByLoanIdAndNotStatus(@Param(value = "loanId") String loanId,
                                                         @Param(value = "status") String status,
                                                         @Param(value = "customerId") String customerId,
                                                         @Param(value = "tenantId") String tenantId);


    /**
     * 根据修改时间查询还款计划
     * @param startTime
     * @return
     */
    List<AmStageRepaymentPlanInfo> selectByUpdateTime(@Param("startTime") String startTime);

    /**
     * 批量插入还款计划
     *
     * @param amRepaymentPlanInfoList 还款计划列表
     * @return void
     * @author : zhenghaopu
     * date: 2019/9/25
     */
    void insertAmStageRepaymentPlanInfoListForMove(List<AmStageRepaymentPlanInfo> amRepaymentPlanInfoList);

    /**
     * 根据账户状态，结清日期，更新时间查询还款计划id
     *
     * @param statusList 账户状态
     * @param payoffDate 结清日期
     * @param startTime
     * @return Set<Long>
     * @author liuyang
     * @date 2021-03-14
     */
    Set<Long> selectIdByStatusUpdateTime(@Param("statusList") List<String> statusList,
                                         @Param("payoffDate") Date payoffDate,
                                         @Param("startTime") Date startTime);

    /**
     * 根据客户编号，聚合计算出指定状态的还款计划信息
     * 详情见sql语句实现
     * @param customerId
     * @param statusList
     * @param tenantId
     * @return
     */
    AmStageRepaymentPlanInfo aggPlansByCustomerId(@Param("customerId") String customerId,
                                             @Param("statusList") List<String> statusList,
                                             @Param("tenantId") String tenantId);

    /**
     * 客户还款日是否存在未结订单
     * @param customerId
     * @param tenantId
     * @param planStatusList
     * @param paymentDueDate
     * @return
     */
    int selectByCustomerAndPlanStatusList(@Param(value = "customerId") String customerId,
                                          @Param(value = "tenantId") String tenantId,
                                          @Param(value = "planStatusList") List<String> planStatusList,
                                          @Param(value = "paymentDueDate") Date paymentDueDate);
}
